﻿@model List<iChip.Hotspots.Models.Splash>
@{
    ViewBag.Title = "Quản Lý Splash";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}
<!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->
<div id="modalMethod" class="modal fade" tabindex="-1" data-width="400">
    <div class="modal-dialog">
        <div class="modal-content">

        </div>
    </div>
</div>
<!-- /.modal -->
<!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->
<!-- BEGIN PAGE HEADER-->
<div class="row">
    <div class="col-md-12">
        <!-- BEGIN PAGE TITLE & BREADCRUMB-->
        <h3 class="page-title">
            Quản Lý Splash
        </h3>
        <ul class="page-breadcrumb breadcrumb">
            <li>
                <i class="icon-home"></i>
                <a href="/Admin">Tổng quan</a>
                <i class="icon-angle-right"></i>
            </li>
            <li><a href="javascript:window.history.back();">Quản lý Splash</a></li>
            <li class="pull-right">
            </li>
        </ul>
        <!-- END PAGE TITLE & BREADCRUMB-->
    </div>
</div>
<!-- END PAGE HEADER-->
<div class="row">
    <div class="col-md-12 col-sm-12">
        <!-- BEGIN EXAMPLE TABLE PORTLET-->
        <div class="portlet">
            <div class="portlet-title">
                <div class="caption"><i class="icon-list-alt"></i>Danh sách Splash của hotspot @ViewBag.Hotspot_Mac</div>
                <div class="actions">
                    <a href="@Url.Action("AddSplash", "Admin", new  { Hotspot_id = @ViewBag.Hotspot_id, Hotspot_mac = @ViewBag.Hotspot_Mac, returnUrl=@Request.RawUrl})" class="btn red"><i class="icon-plus"></i> Thêm mới Splash</a>
                </div>
            </div>
            <div class="portlet-body">
                @if (Model != null && Model.Count > 0)
                {
                    <div class="table-responsive">
                        <table class="table table-striped table-bordered table-advance table-hover" id="tbHotspots">
                            <thead>
                                <tr>
                                    <th>Tên Splash</th>
                                    <th>Hotspot Mac</th>
                                    <th>Nhóm Khách Hàng</th>
                                    <th>Bắt Đầu</th>
                                    <th>Kết Thúc</th>
                                    <th>Link Đích</th>
                                    <th>Tùy chọn</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (var item in Model)
                                {
                                    <tr class="odd gradeX" id="trSplash_@item.Splash_Id">
                                        <td>@item.Splash_Name</td>
                                        <td>@item.Hotspot_Mac</td>
                                        <td>
                                            @if (item.User_Type == (int)iChip.Hotspots.Commons.Enums.UserType.VIP) // VIP
                                            {
                                                <span class="label label-sm label-danger">VIP</span>
                                            }
                                            else if (item.User_Type == (int)iChip.Hotspots.Commons.Enums.UserType.Personal)
                                            {
                                                <span class="label label-sm label-warning">Cá Nhân</span>
                                            }
                                            else if (item.User_Type == (int)iChip.Hotspots.Commons.Enums.UserType.Enterprise)
                                            {
                                                <span class="label label-sm label-success">Doanh Nghiệp</span>
                                            }
                                            else
                                            {
                                                <span class="label label-sm label-default">Mặc Định</span>
                                            }
                                        </td>
                                        <td>@Convert.ToDateTime(item.Splash_StartTime).ToString("dd/MM/yyyy")</td>
                                        <td>@Convert.ToDateTime(item.Splash_EndTime).ToString("dd/MM/yyyy")</td>
                                        <td>@item.Splash_UrlRedirect</td>
                                        <td>
                                            <a name="aEdit" href="@Url.Action("AddSplash", "Admin", new { splash_id = @item.Splash_Id, Hotspot_id = @ViewBag.Hotspot_id, Hotspot_mac = @ViewBag.Hotspot_Mac, returnUrl = @Request.RawUrl })" data-id="@item.Splash_Id" class="btn btn-default btn-xs purple"><i class="icon-pencil"></i> Sửa</a>&nbsp;
                                            @*<a href="#" data-splashid="@item.Splash_Id" class="btn btn-default purple" onclick="showModal(this)"><i class="icon-pencil"></i> Method</a>&nbsp;*@
                                            <a href="@Url.Action("AddMethod","Admin", new { splash_id = @item.Splash_Id })" data-splashid="@item.Splash_Id" class="btn btn-default btn-xs blue"><i class="icon-lock"></i> Phương Thức</a>&nbsp;
                                            @if (!item.Splash_IsDefault)
{
    <a name="aDel" data-id="@item.Splash_Id" class="btn btn-default btn-xs red"><i class="icon-trash"></i> Xóa</a>
}
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                }
            </div>
        </div>
        <!-- END EXAMPLE TABLE PORTLET-->
    </div>
</div>

@section Scripts {
    <script>
        function showModal(el) {
            console.log($(el), $(el).data("splashid"));
            $.ajax({
                cache: false,
                type: 'POST',
                url: '@Url.Action("ListMethods", "Admin")',
                data: {
                    splash_id: $(el).data("splashid"),
                    returnUrl: '@Request.RawUrl'
                },
                success: function (data) {
                    $("#modalMethod").find(".modal-content").html(data);
                    $('#modalMethod').modal('show');
                }
            });

        }

        $("[name=aDel]").click(function (e) {
            e.preventDefault();
            var r = confirm("Bạn có thực sự muốn xóa Splash này ra khỏi hệ thống!");
            if (r == true) {
                var id = $(this).data("id");
                $.ajax({
                    url: '@Url.Action("DeleteSplash", "Admin")', //this is the submit URL
                    type: 'POST', //or POST
                    data: { splash_id: id },
                    success: function (data) {
                        if (data.Status == true) {
                            $("#trSplash_" + id).remove();
                        }
                        else {
                            alert(data.Message);
                        }
                    }
                });
            }
        });
    </script>

}